import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_flutter_app/generated/l10n.dart';
import 'package:my_flutter_app/themes/index.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<StatefulWidget> createState() => _MyHomePage();
}

class _MyHomePage extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
  }

  List<Widget> _getListData(BuildContext context) {
    List listData = [
      {
        'title': S.current.devicesTitle,
        'routerPath': '/device_info',
      },
      {
        'title': S.current.photoAndCameraTitle,
        'routerPath': '/image_picker',
      },
      {
        'title': S.current.locationTitle,
        'routerPath': '/location',
      },
      {
        'title': S.current.contactsTitle,
        'routerPath': '/contacts',
      },
      {
        'title': S.current.soundTitle,
        'routerPath': '/sound',
      },
      {
        'title': S.current.nativeTitle,
        'routerPath': '/native',
      },
      {
        'title': S.current.webTitle,
        'routerPath': '/web',
      },
      {
        'title': S.current.webOffTitle,
        'routerPath': '/web-off',
      },
      {
        'title': S.current.loginTitle,
        'routerPath': '/login',
      },
      {
        'title': S.current.login2Title,
        'routerPath': '/login2',
      },
      {
        'title': S.current.uniTitle,
        'routerPath': '/uni',
      }
    ];
    List<Widget> widgets = [];
    for (int i = 0; i < listData.length; i++) {
      Map<String, String> data = listData[i];
      widgets.add(GestureDetector(
          onTap: () {
            // Navigator.of(context).pushNamed(data['routerPath']!);
            Get.toNamed(data['routerPath']!);
          },
          child: Container(
            child: Text(data['title']!),
            padding:
                EdgeInsets.only(top: 10.0, left: 10.0, bottom: 10.0), // 添加内边距
            decoration: BoxDecoration(
                border:
                    Border(bottom: BorderSide(color: Colors.grey, width: 0.5))),
          )));
    }
    return widgets;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(S.current.title),
      ),
      body: ListView(
        children: _getListData(context),
      ),
      floatingActionButton:
          Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
        Semantics(
          label: 'image_picker_example_from_gallery',
          child: FloatingActionButton(
            onPressed: () {
              const locale = Locale('zh', 'CN');
              Get.updateLocale(locale);
            },
            heroTag: 'image0',
            tooltip: '切换中文',
            child: const Text('中'),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 16.0),
          child: FloatingActionButton(
            onPressed: () {
              const locale = Locale('en', 'US');
              Get.updateLocale(locale);
            },
            tooltip: 'Switch English',
            child: const Text('En'),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 16.0),
          child: FloatingActionButton(
            onPressed: () {
              Get.changeTheme(Themes.light);
            },
            tooltip: 'Switch English',
            child: const Text('亮'),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 16.0),
          child: FloatingActionButton(
            onPressed: () {
              Get.changeTheme(Themes.dark);
            },
            tooltip: 'Switch English',
            child: const Text('暗'),
          ),
        ),
      ]),
    );
  }
}
